<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ page contentType = "text/html; charset=UTF-8" %>

<html>
<head>

<c:set var="cssFileName">
	<c:out value="${crudViewMeta.cssFileName}" default="default.css"/>
</c:set>
<link rel="stylesheet" href="<c:url value='/css/${cssFileName}'/>" type="text/css">
<link rel="stylesheet" href="<c:url value='/css/calendar-win2k-1.css'/>">

<title><c:out value="${crudMeta.title}"/>数据编辑页面</title>

<script type="text/javascript" src="<c:url value='/javascript/calendar.js'/>"></script>
<script type="text/javascript" src="<c:url value='/javascript/lang/calendar-zh.js'/>"></script>
<script type="text/javascript" src="<c:url value='/javascript/calendar-setup.js'/>"></script>

<script type="text/javascript">

function gotoListView()
{
	window.location="<c:url value='/list.do'><c:param name='name' value='${crudMeta.beanName}'/>
	<c:forEach items='${crudMeta.otherWantedParameters}' var='wantedParam'>
    	<c:param name='${wantedParam}' value='${param[wantedParam]}'/>
    </c:forEach></c:url>";
}

</script>

</head>

<body>

<table class="top" align="center">
	<tr><td class="headtitle">编辑<c:out value="${crudMeta.title}"/></td></tr>
</table>

<form name="editSingleForm" action="<c:url value='/editSingle.do'/>" method="POST"/>
	<input type="hidden" name="name" value="<c:out value='${crudMeta.beanName}'/>"/>
	<c:forEach items="${crudMeta.otherWantedParameters}" var="wantedParam">
		<input type="hidden" name="<c:out value='${wantedParam}'/>" value="<c:out value='${param[wantedParam]}'/>">
	</c:forEach>
	
	<table class="content">
		<c:forEach items="${crudMeta.columnMetas}" var="col">
			<spring:bind path="command.mapContent[${col.colName}]">
	     		<c:set var="validateError"><c:out value="${status.errorMessage}"/></c:set>
			</spring:bind>
		
	  		<c:if test="${!col.derived}">
	  			<spring:bind path="command.mapContentBefore[${col.colName}]">
					<input type="hidden" name="<c:out value='${status.expression}'/>" value="<c:out value='${status.value}'/>">
				</spring:bind>
	  		</c:if>
			<c:if test="${col.showInEditForm}">
				<tr class="body">
				
				<!--列名称-->
				<td class="head">
					<c:if test="${empty validateError}"><c:out value="${col.title}"/></c:if>
      				<c:if test="${not empty validateError}"><span class="validateError"><c:out value="${col.title}"/></span></c:if>
      				<c:if test="${!col.nullable}"><span class="notNullHint">*</span></c:if>
      			</td>
					
				<td>
				
				<!--如果该列是引申而来的，显示数据的同时也需要提供表单元素，否则在校验不通过的时候无法显示其值-->
				<c:if test="${col.derived}">
					<spring:bind path="command.mapContent[${col.colName}]">
	  					<input type="hidden" 
	  						name="<c:out value='${status.expression}'/>" 
	  						value="<c:out value='${status.value}'/>">
	      			</spring:bind>
					<c:if test="${empty col.dictName || !col.needDictReplace}">
						<c:out value="${command.mapContent[col.colName]}"/>
					</c:if>
					<c:if test="${not empty col.dictName && col.needDictReplace}">
						<c:out value="${col.dictMap[command.mapContent[col.colName]]}"/>
					</c:if>
				</c:if>
				
				<c:if test="${!col.derived}">
					<!--如果该列不可编辑-->
		  			<c:if test="${!col.editable}">
	  					<spring:bind path="command.mapContent[${col.colName}]">
	  					<input type="hidden" 
	  						name="<c:out value='${status.expression}'/>" 
	  						value="<c:out value='${status.value}'/>">
	      				</spring:bind>
	      				<c:out value='${command.mapContent[col.colName]}'/>			
			      	</c:if>
		      		
  					<!--如果该列没有字典，使用文本框作为表单元素-->
	      			<c:if test="${col.editable && empty col.dictName}">
	      				
	      				<!--如果用户可以直接手工输入，或者没有dispPattern，则使用一个表单元素就可以了-->
	      				<c:if test="${col.directInputable}">
		  					<spring:bind path="command.mapContent[${col.colName}]">
		  					<input type="text" id="input_<c:out value='${col.colName}'/>"
		  						name="<c:out value='${status.expression}'/>" 
		  						value="<c:out value='${status.value}'/>" <c:if test="${!col.directInputable}">readonly</c:if>>
			      			</spring:bind>
			      			<c:if test="${not empty col.inputValueSelectViewName}">
			      				<c:import url="/WEB-INF/jsp/crud/inputValueSelect/${col.inputValueSelectViewName}.jsp">
			      					<c:param name="name" value="${crudMeta.beanName}"/>
			      					<c:param name="formItemName" value="mapContent[${col.colName}]"/>
			      					<c:param name="formItemId" value="input_${col.colName}"/>
			      				</c:import>
			      			</c:if>
		      			</c:if>
		      			
		      			<!--如果用户不可以直接手工输入-->
		      			<c:if test="${!col.directInputable}">
		      				<spring:bind path="command.mapContent[${col.colName}]">
		  					<input type="hidden" id="ID_<c:out value='${col.colName}'/>"
		  						name="<c:out value='${status.expression}'/>" 
		  						value="<c:out value='${status.value}'/>" <c:if test="${!col.directInputable}">readonly</c:if>
		  						onchange="javascript:<c:out value='${col.colName}'/>_onchange();">
			      			</spring:bind>
			      			<input type="text" name="DISP_<c:out value='${col.colName}'/>" disabled>
			      			<c:if test="${not empty col.inputValueSelectViewName}">
			      				<c:import url="/WEB-INF/jsp/crud/inputValueSelect/${col.inputValueSelectViewName}.jsp">
			      					<c:param name="name" value="${crudMeta.beanName}"/>
			      					<c:param name="colName" value="${col.colName}"/>
			      					<c:param name="formItemName" value="mapContent[${col.colName}]"/>
			      					<c:param name="formItemId" value="ID_${col.colName}"/>
			      					<c:param name="formItem4DispName" value="DISP_${col.colName}"/>
			      				</c:import>
			      			</c:if>
		      			</c:if>
		      		</c:if>
		      		
  					<!--如果有字典，则需要使用下拉框来展现-->
		  			<c:if test="${col.editable && not empty col.dictName}">
	  					<spring:bind path="command.mapContent[${col.colName}]">
						<select name="<c:out value='${status.expression}'/>">
							<c:if test="${!col.primaryKey && col.nullable}"><option value="">(未选取)</option></c:if>
							<c:forEach var="map" items="${col.dictMap}">										
								<option value='<c:out value="${map.key}"/>' <c:if test="${map.key == status.value}">selected="selected"</c:if>><c:out value="${map.value}"/></option>
							</c:forEach>
						</select>
						</spring:bind>
					</c:if>
  				</c:if>
  				
  				<!--如果有提示信息的话-->
  				&nbsp;&nbsp;<span class="hint"><c:out value="${col.hint}"/></span>
				<!--仅仅为了形式上的美观-->
				<c:if test="${not empty col.hint}">&nbsp;&nbsp;</c:if>
				<!--显示校验信息-->
				<span class="validateError"><c:out value="${validateError}"/></span>
					
  				</td>
  			</tr>
      	</c:if>
				
		<!--如果该列不显示在表单中，也需要使用hidden表单元素将其值POST出去-->
		<c:if test="${!col.showInEditForm && !col.derived}">
			<spring:bind path="command.mapContent[${col.colName}]">
			<input type="hidden" 
				name="<c:out value='${status.expression}'/>" 
				value="<c:out value='${status.value}'/>">
			</spring:bind>				
		</c:if>
			
	</c:forEach>	
</table>

<br>
	
<table>
	<tr align="center" valign="center">
		<td align="left" width="50%">
			<input type="submit" name="save" value="保存">
			<input type="button" name="back" value="返回" onclick="javascript:gotoListView()">
		</td>
		<td width="50%">
		</td>
	</tr>
</table>
 	
</form>
</body>
</html>